package ae.pcfc.cldos.online.common.factories;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import ae.pcfc.cldos.online.common.clddb.domain.AddressDetail;
import ae.pcfc.cldos.online.common.clddb.domain.AppMetaData;
import ae.pcfc.cldos.online.common.clddb.domain.EmployeeDetail;
import ae.pcfc.cldos.online.common.clddb.domain.EmploymentVisaCancel;
import ae.pcfc.cldos.online.common.clddb.domain.EmploymentVisaRenew;
import ae.pcfc.cldos.online.common.clddb.domain.NocLetter;
import ae.pcfc.cldos.online.common.clddb.domain.PassportDetail;
import ae.pcfc.cldos.online.common.clddb.domain.PersonalDetail;
import ae.pcfc.cldos.online.common.clddb.domain.TempFileStorage;
import ae.pcfc.cldos.online.common.clddb.domain.VisitVisa;
import ae.pcfc.cldos.online.common.clddb.domain.VisitVisaCancel;

/**
 * 
 * @author arosa
 *
 */
public class AppMetaDataFactory {

	private AppMetaData appMetaData;
	private String clientReferenceNo;
	
	private AppMetaDataFactory(AppMetaData appMetaData){
		this.appMetaData = appMetaData;
	}
	
	private AppMetaDataFactory(String clientReferenceNo){
		this.clientReferenceNo = clientReferenceNo;
	}
	
	public static AppMetaDataFactory createSubmitFactory(String clientReferenceNo){
		return new AppMetaDataFactory(clientReferenceNo); 
	}
	
	public static AppMetaDataFactory createReSubmitFactory(AppMetaData appMetaData){
		return new AppMetaDataFactory(appMetaData); 
	}
	
	public AppMetaData getAppMetaData(){
		AppMetaData appMetaData = null;
		if(this.appMetaData==null){
			appMetaData = new AppMetaData();
			appMetaData.setClientRefNo(clientReferenceNo);
		} else {
			appMetaData = this.appMetaData;
		}
		return appMetaData;
	}
	
	public EmployeeDetail getEmployeeDetails(){
		EmployeeDetail employeeDetail = null;
		if(this.appMetaData==null || this.appMetaData.getEmployeeDetail()==null){
			employeeDetail = new EmployeeDetail();
		}else {
			employeeDetail = this.appMetaData.getEmployeeDetail();
		}
		return employeeDetail;
	}
	
	public VisitVisa getVisitVisa(){
		VisitVisa visitVisa = null;
		if(this.appMetaData==null || this.appMetaData.getVisitVisa()== null){
			visitVisa = new VisitVisa();
		}else {
			visitVisa = this.appMetaData.getVisitVisa();
		}
		return visitVisa;
	}
	
	public AddressDetail getAddressDetail(){
		AddressDetail addressDetail = null;
		if(this.appMetaData==null || this.appMetaData.getEmployeeDetail()==null
				|| this.appMetaData.getEmployeeDetail().getAddressDetail()==null){
			addressDetail = new AddressDetail();
		}else {
			addressDetail = this.appMetaData.getEmployeeDetail().getAddressDetail();
		}
		return addressDetail;
	}
	
	public PersonalDetail getPersonalDetail(){
		PersonalDetail personalDetail = null;
		if(this.appMetaData==null || this.appMetaData.getEmployeeDetail()==null
				|| this.appMetaData.getEmployeeDetail().getPersonalDetail()==null){
			personalDetail = new PersonalDetail();
		}else {
			personalDetail = this.appMetaData.getEmployeeDetail().getPersonalDetail();
		}
		return personalDetail;
	}
	
	public PassportDetail getPassportDetail(){
		PassportDetail passportDetail = null;
		if(this.appMetaData==null || this.appMetaData.getEmployeeDetail()==null
				|| this.appMetaData.getEmployeeDetail().getPassportDetail()==null){
			passportDetail = new PassportDetail();
		}else {
			passportDetail = this.appMetaData.getEmployeeDetail().getPassportDetail();
		}
		return passportDetail;
	}
	
	public EmploymentVisaCancel getEmploymentVisaCancel(){
		EmploymentVisaCancel employmentVisaCancel = null;
		if(this.appMetaData==null || this.appMetaData.getEmploymentVisaCancel()==null){
			employmentVisaCancel = new EmploymentVisaCancel();
		} else {
			employmentVisaCancel = this.appMetaData.getEmploymentVisaCancel();
		}
		return employmentVisaCancel;
	}
	
	public VisitVisaCancel getVisitVisaCancel(){
		VisitVisaCancel visitVisaCancel = null;
		if(this.appMetaData==null || this.appMetaData.getVisitVisaCancel()==null){
			visitVisaCancel = new VisitVisaCancel();
		} else {
			visitVisaCancel = this.appMetaData.getVisitVisaCancel();
		}
		return visitVisaCancel;
	}
	
	public EmploymentVisaRenew getEmploymentVisaRenew(){
		EmploymentVisaRenew employmentVisaRenew = null;
		if(this.appMetaData==null || this.appMetaData.getEmploymentVisaRenew()==null){
			employmentVisaRenew = new EmploymentVisaRenew();
		} else {
			employmentVisaRenew = this.appMetaData.getEmploymentVisaRenew();
		}
		return employmentVisaRenew;
	}
	
	public NocLetter getNocLetter(){
		NocLetter nocLetter = null;
		if(this.appMetaData==null || this.appMetaData.getNocLetter()==null){
			nocLetter = new NocLetter();
		} else {
			nocLetter = this.appMetaData.getNocLetter();
		}
		return nocLetter;
	}
	
	@SuppressWarnings("unchecked")
	public Map<String, TempFileStorage> getTempFileStoragesMap(){
		Map<String, TempFileStorage> tempFileStoragesMap = null;
		if(this.appMetaData==null || this.appMetaData.getTempFileStorages()==null){
			tempFileStoragesMap = (Map<String, TempFileStorage>)Collections.EMPTY_MAP;
		}else {
			tempFileStoragesMap = new HashMap<String, TempFileStorage>(this.appMetaData.getTempFileStorages().size());
			for(TempFileStorage tempFileStorage :this.appMetaData.getTempFileStorages()){
				tempFileStoragesMap.put(tempFileStorage.getAttachmentTypeCode(), tempFileStorage);
			}
		}
		return tempFileStoragesMap;
	}
}
